import { isFunction } from '@vue/shared'

const useUnMounted = (fn) => {
    const func = isFunction(fn) ? fn : () => { }
    const instance = getCurrentInstance()
    if (!instance) return false
    let timeout = null
    onDeactivated(() => {
        clearTimeout(timeout)
        timeout = setTimeout(() => {
            func()
        });
    })

    onUnmounted(() => {
        timeout = setTimeout(() => {
            func()
        })
    });
    return true
}


export default useUnMounted